package com.checx.delegating;

import java.io.IOException;

// <C, MyClassLoader> <Delegate, AppClassLoader>
// Delegate由AppClassLoader加载,delegated.getSpoofed()执行时其中的Spoofed类也由AppClassLoader加载
// f() 中的Spoofed由MyClassLoader加载
// 事先要先准备两个版本的Spoofed.class，伪造的放到./classes下由MyClassLoader加载
public class C {
    public void f() throws IOException {
        // 此处加载伪造的Spoofed.class
        Spoofed spoofed1 = new Spoofed();
        System.out.println(spoofed1);
        Delegated delegated = new Delegated();
        Spoofed spoofed = delegated.getSpoofed();
        // 获取到伪造的Spoofed类的secretVal字段
        System.out.println(spoofed.secretVal);
    }
}
